package com.zhdl.modules.demo.web;

import com.project.network.conf.LinkClientBuild;
import com.zhdl.network.common_client.CommonSerialClientAfter;
import com.zhdl.network.common_client.CommonSerialClientAnalysis;
import com.zhdl.network.common_client.CommonTcpClientAfter;
import com.zhdl.network.common_client.CommonTcpClientAnalysis;
import com.zhdl.network.strategy.common_client.CommonProtocolService;
import com.zhdl.network.strategy.common_client.dto.SendReceiverData;
import com.zhdl.network.strategy.common_server.impl.CommonServerSendServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Slf4j
@Service
public class CommonProtocolTestService {

    @Resource
    private CommonServerSendServiceImpl commonServerSendServiceImpl;


    @Autowired
    private CommonProtocolService commonProtocolService;
    @Autowired
    private LinkClientBuild com;

    public void send() {
        commonProtocolService.sendCmd("", "");
    }

    public void init() {
        SendReceiverData sendReceiverData = new SendReceiverData();
        sendReceiverData.setPort("1");
        sendReceiverData.setProtocols(CommonSerialClientAnalysis.MODBUS_ANALYSIS);
        sendReceiverData.setAfter(CommonSerialClientAfter.MODBUS_RTU_AFTER_SERVICE);
        commonProtocolService.initPort(sendReceiverData);
        SendReceiverData sendReceiverData1 = new SendReceiverData();
        sendReceiverData1.setPort("2");
        sendReceiverData1.setProtocols(CommonSerialClientAnalysis.MODBUS_ANALYSIS);
        sendReceiverData1.setAfter(CommonSerialClientAfter.MODBUS_RTU_AFTER_SERVICE);
        commonProtocolService.initPort(sendReceiverData1);
        SendReceiverData sendReceiverData2 = new SendReceiverData();
        sendReceiverData2.setPort("127.0.0.1:6666");
        sendReceiverData2.setProtocols(CommonTcpClientAnalysis.COMMON_TCP_ANALYSIS);
        sendReceiverData2.setAfter(CommonTcpClientAfter.COMMON_TCP_AFTER_SERVICE);
        commonProtocolService.initPort(sendReceiverData2);
        SendReceiverData sendReceiverData3 = new SendReceiverData();
        sendReceiverData3.setPort("127.0.0.1:8888");
        sendReceiverData3.setProtocols(CommonTcpClientAnalysis.COMMON_TCP_ANALYSIS);
        sendReceiverData3.setAfter(CommonTcpClientAfter.COMMON_TCP_AFTER_SERVICE);
        commonProtocolService.initPort(sendReceiverData3);

        commonServerSendServiceImpl.addServer("127.0.0.1:6000");
        commonServerSendServiceImpl.addServer("127.0.0.1:8000");
    }

}
